/*
 #
 #  Files       : BinaryTraits.h
 #                ( C++ header file )
 #
 #  Description : The SmallMatrix Library
 #                ( http://code.google.com/p/smallmatrix )
 #
 #  Copyright   : Olivier Juan
 #                ( http://www.mas.ecp.fr/vision/Personnel/juan/ )
 #
 #  License     : CeCILL-C
 #                ( http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html )
 #
 #  This software is governed by the CeCILL-C license under French law and
 #  abiding by the rules of distribution of free software.  You can  use,
 #  modify and or redistribute the software under the terms of the CeCILL-C
 #  license as circulated by CEA, CNRS and INRIA at the following URL
 #  "http://www.cecill.info".
 #
 #  As a counterpart to the access to the source code and  rights to copy,
 #  modify and redistribute granted by the license, users are provided only
 #  with a limited warranty  and the software's author,  the holder of the
 #  economic rights,  and the successive licensors  have only  limited
 #  liability.
 #
 #  In this respect, the user's attention is drawn to the risks associated
 #  with loading,  using,  modifying and/or developing or reproducing the
 #  software by the user in light of its specific status of free software,
 #  that may mean  that it is complicated to manipulate,  and  that  also
 #  therefore means  that it is reserved for developers  and  experienced
 #  professionals having in-depth computer knowledge. Users are therefore
 #  encouraged to load and test the software's suitability as regards their
 #  requirements in conditions enabling the security of their systems and/or
 #  data to be ensured and,  more generally, to use and operate it in the
 #  same conditions as regards security.
 #
 #  The fact that you are presently reading this means that you have had
 #  knowledge of the CeCILL-C license and that you accept its terms.
 #
*/

#ifndef _BINARYTRAITS_H
#define _BINARYTRAITS_H

#include <SmallMatrix/SmallMatrix.h>

NAMESPACE_BEGIN(SmallMatrix)

template <bool> struct STATIC_ASSERTION_FAILURE;

template <> struct STATIC_ASSERTION_FAILURE<true> {};

template<int x> struct static_assert_test{};

#define STATIC_ASSERT( B ) \
   typedef static_assert_test<\
      sizeof(STATIC_ASSERTION_FAILURE< (bool)( B ) >)>\
	  static_assert_typedef_##__LINE__


template <typename T1,typename T2> struct STATIC_EGALITY_ASSERTION_FAILURE;

template <typename T> struct STATIC_EGALITY_ASSERTION_FAILURE<T,T> {};

template<int x> struct static_egality_assert_test{};

#define STATIC_EGALITY_ASSERT( A , B ) \
   typedef static_egality_assert_test<\
      sizeof(STATIC_EGALITY_ASSERTION_FAILURE< A , B >)>\
	  static_egality_assert_typedef_##__LINE__


template <class T1,class T2> struct Matrix_Product_Scheme_Trait {
	typedef T1 result_type;
};

template <int K,int L,int M,int N> struct Matrix_Product_Scheme_Trait< Matrix<K,L> , Matrix<M,N> > {
	STATIC_ASSERT(L==M);
	typedef Matrix<K,N> result_type;
};
template <int K,int L,int M> struct Matrix_Product_Scheme_Trait< Matrix<K,L> , Matrix<M,K> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<K> result_type;
};
template <int K,int L,int M> struct Matrix_Product_Scheme_Trait< Matrix<K,L> , SquareMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef Matrix<K,M> result_type;
};
template <int K,int L,int M> struct Matrix_Product_Scheme_Trait< Matrix<K,L> , SymMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef Matrix<K,M> result_type;
};
template <int K,int L,int M> struct Matrix_Product_Scheme_Trait< Matrix<K,L> , Vecteur<M> > {
	STATIC_ASSERT(L==M);
	typedef Vecteur<K> result_type;
};
template <int L,int M,int N> struct Matrix_Product_Scheme_Trait< SquareMatrix<L> , Matrix<M,N> > {
	STATIC_ASSERT(L==M);
	typedef Matrix<M,N> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SquareMatrix<L> , SquareMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<M> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SquareMatrix<L> , SymMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<M> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SquareMatrix<L> , Vecteur<M> > {
	STATIC_ASSERT(L==M);
	typedef Vecteur<L> result_type;
};
template <int L,int M,int N> struct Matrix_Product_Scheme_Trait< SymMatrix<L> , Matrix<M,N> > {
	STATIC_ASSERT(L==M);
	typedef Matrix<M,N> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SymMatrix<L> , SquareMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<M> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SymMatrix<L> , SymMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SymMatrix<M> result_type;
};
template <int L,int M> struct Matrix_Product_Scheme_Trait< SymMatrix<L> , Vecteur<M> > {
	STATIC_ASSERT(L==M);
	typedef Vecteur<L> result_type;
};



template <class T1,class T2> struct Matrix_Additive_Scheme_Trait {
	typedef T1 result_type;
};

template <int K,int L,int M,int N> struct Matrix_Additive_Scheme_Trait< Matrix<K,L> , Matrix<M,N> > {
	STATIC_ASSERT( ((K==M) && (L==N)) );
	//STATIC_ASSERT(L==N);
	typedef Matrix<K,N> result_type;
};
template <int K,int L,int M> struct Matrix_Additive_Scheme_Trait< Matrix<K,L> , SquareMatrix<M> > {
	STATIC_ASSERT( (L==M) && (K==M) );
	//STATIC_ASSERT(K==M);
	typedef SquareMatrix<M> result_type;
};
template <int K,int L,int M> struct Matrix_Additive_Scheme_Trait< Matrix<K,L> , SymMatrix<M> > {
	STATIC_ASSERT( (L==M) && (K==M) );
	//STATIC_ASSERT(K==M);
	typedef SquareMatrix<M> result_type;
};
template <int L,int M,int N> struct Matrix_Additive_Scheme_Trait< SquareMatrix<L> , Matrix<M,N> > {
	STATIC_ASSERT( (L==M) && (L==N) );
	//STATIC_ASSERT(L==N);
	typedef SquareMatrix<L> result_type;
};
template <int L,int M> struct Matrix_Additive_Scheme_Trait< SquareMatrix<L> , SquareMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<L> result_type;
};
template <int L,int M> struct Matrix_Additive_Scheme_Trait< SquareMatrix<L> , SymMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<L> result_type;
};
template <int L,int M,int N> struct Matrix_Additive_Scheme_Trait< SymMatrix<L> , Matrix<M,N> > {
	STATIC_ASSERT( (L==M) && (L==N) );
	//STATIC_ASSERT(L==N);
	typedef SquareMatrix<L> result_type;
};
template <int L,int M> struct Matrix_Additive_Scheme_Trait< SymMatrix<L> , SquareMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<L> result_type;
};
template <int L,int M> struct Matrix_Additive_Scheme_Trait< SymMatrix<L> , SymMatrix<M> > {
	STATIC_ASSERT(L==M);
	typedef SquareMatrix<L> result_type;
};



template <class T1,class T2> class Matrix_Strictly_Additive_Scheme_Trait {
	typedef typename Matrix_Additive_Scheme_Trait<T1,T2>::result_type T3;
	STATIC_EGALITY_ASSERT( T1 , T3 );
public:
	typedef T1 result_type;
};


NAMESPACE_END
#endif
